package com.choosefine.base.attendance.client.device

import Com.FirstSolver.Splash.FaceId_Item
import com.choosefine.base.attendance.client.record.AttendanceRecordDao
import com.choosefine.base.common.bean.ToolkitBean
import com.google.common.base.CaseFormat
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

/**
 * Created by 邱鹏 on 2017/8/29.
 */
@Service
class DeviceApiBean {
    @Autowired lateinit var toolkit: ToolkitBean
    @Autowired lateinit var recordDao: AttendanceRecordDao
    open fun convert() {

    }

    fun faceIdTtemToMap(str: String): MutableMap<String, Any> {
        var item: MutableMap<String, Any> = mutableMapOf()
        FaceId_Item.GetAllItems(str).forEach { x ->
            val name = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, x.name)
            item.put(name, x.value)
        }
        return item
    }

    fun saveMachineInfo(machineInfo: String) {
        var machineInfoMap = faceIdTtemToMap(machineInfo)
        recordDao.saveMachineInfo(machineInfoMap)
    }

    fun saveRecord(recordList: MutableList<String>, machineInfo: String) {
        var rList: MutableList<MutableMap<String, Any>> = mutableListOf()
        recordList.forEach {
            rList.add(faceIdTtemToMap(it))
        }
        var machineInfoMap = faceIdTtemToMap(machineInfo)
        val param = mutableMapOf("recordList" to rList, "deviceId" to machineInfoMap.get("devId")!!)
        recordDao.saveRecord(param)
    }
}

